package com.china08.yxyapi.service.mg.impl;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.china08.yxyapi.entity.mg.user.YxyUserCenter;
import com.china08.yxyapi.repository.mg.YxyUserCenterRepository;
import com.china08.yxyapi.service.mg.YxyUserCenterService;

@Service
public class YxyUserCenterServiceImpl implements YxyUserCenterService {

    @Autowired
    private YxyUserCenterRepository yucr;

    @Override
    @Transactional
    public YxyUserCenter getYxUserCenter(String userId) {
        YxyUserCenter center = yucr.findByUserId(userId);
        if (center == null) {
            center = new YxyUserCenter();
            center.setUserId(userId);
            center = yucr.save(center);
        }
        return center;
    }

    @Override
    public void updYxUserCenterRes(YxyUserCenter center, String phase, String subject, String version,
            String subjectName, String phaseName, String versionName, String bookId, String semester,
            String semesterName) {
        center.setResView(phase, subject, version, subjectName, phaseName, versionName, bookId, semester, semesterName);
        yucr.save(center);
    }

    @Override
    public void updYxUserCenterWeike(YxyUserCenter center, String phase, String subject, String stageName,
            String subjectName) {
        center.setWeikeView(phase, subject, subjectName, stageName);
        yucr.save(center);
    }

    @Override
    public void updYxUserCenterWeikeContent(YxyUserCenter center, String phase, String subject, String version,
            String subjectName, String phaseName, String versionName, String bookId, String semester,
            String semesterName) {
        center.setWeikeContentView(phase, subject, version, subjectName, phaseName, versionName, bookId, semester,
                semesterName);
        yucr.save(center);

    }

}
